#include<bits/stdc++.h>
using namespace std;

struct cow{
	int w,s;	
	int sum;
	bool operator <(cow c){
		return sum<c.sum;
	}
};
int main(){
	int n,s=0,k;
	cin>>n;
	vector<cow> c(n);
	for(int i=0;i<n;i++) {
		cin>>c[i].w>>c[i].s;
	    c[i].sum=c[i].w+c[i].s;	
	}
	sort(c.begin(),c.end());
	k=-c[0].s;
	for(int i=0;i<n;i++){
		k=max(k,s-c[i].s);
		s+=c[i].w;
	}
	cout<<k;
	return 0;
}
